﻿package mortal.game.view.systemSetting.view
{
    import com.mui.containers.*;
    import com.mui.containers.globalVariable.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import fl.controls.*;
    import flash.events.*;
    import mortal.common.sound.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.systemSetting.*;
    import mortal.mvc.core.*;

    public class SystemSetPanel extends GSprite
    {
        protected var _settingItemArrayLeft:Array;
        protected var _settingItemArrayRight:Array;
        protected var _scrollPaneLeft:GScrollPane;
        protected var _scrollPaneRight:GScrollPane;
        protected var _leftBox:GBox;
        protected var _rightBox:GBox;
        protected var _bgMusicBar:IconProgressBar;
        protected var _effectMusicBar:IconProgressBar;
        protected var _forbitMusicCheckBox:GCheckBox;
        protected var _btnReset:GButton;
        protected var _btnSave:GButton;

        public function SystemSetPanel()
        {
            return;
        }// end function

        override protected function configUI() : void
        {
            var _loc_1:Array = null;
            this._settingItemArrayLeft = new Array();
            this._settingItemArrayRight = new Array();
            _loc_1 = new Array();
            _loc_1.push(SystemSetting.instance.hideSetter);
            _loc_1.push(SystemSetting.instance.hideSetterType);
            _loc_1.push(SystemSetting.instance.playerOnScreen);
            _loc_1.push(SystemSetting.instance.playerOnScreenNum);
            this._settingItemArrayLeft.push({type:"屏蔽玩家", list:_loc_1});
            _loc_1 = new Array();
            _loc_1.push(SystemSetting.instance.effectSetterType);
            this._settingItemArrayLeft.push({type:"画面质量", list:_loc_1});
            _loc_1 = new Array();
            _loc_1.push(SystemSetting.instance.isHideSkill);
            _loc_1.push(SystemSetting.instance.isHideAllEffect);
            _loc_1.push(SystemSetting.instance.isHideFlowerEffect);
            this._settingItemArrayLeft.push({type:"屏蔽游戏特效", list:_loc_1});
            _loc_1 = new Array();
            _loc_1.push(SystemSetting.instance.isHideLife);
            _loc_1.push(SystemSetting.instance.isHideOterPlayerName);
            _loc_1.push(SystemSetting.instance.isHideTitle);
            _loc_1.push(SystemSetting.instance.isHideGuildName);
            this._settingItemArrayLeft.push({type:"屏蔽信息", list:_loc_1});
            _loc_1 = new Array();
            _loc_1.push(SystemSetting.instance.isHideTeamChatBubble);
            _loc_1.push(SystemSetting.instance.isHideSystemTips);
            _loc_1.push(SystemSetting.instance.isHideRumorTips);
            _loc_1.push(SystemSetting.instance.isHideGuildChatPanel);
            this._settingItemArrayLeft.push({type:"屏蔽消息", list:_loc_1});
            _loc_1 = new Array();
            _loc_1.push(SystemSetting.instance.isRefuseTrade);
            _loc_1.push(SystemSetting.instance.isRefuseBeAddToGroup);
            _loc_1.push(SystemSetting.instance.isRefuseBeAddToGuild);
            this._settingItemArrayRight.push({type:"拒绝邀请", list:_loc_1});
            _loc_1 = new Array();
            _loc_1.push(SystemSetting.instance.isSelectFightToDead);
            _loc_1.push(SystemSetting.instance.isNotAutoSelectPlayer);
            _loc_1.push(SystemSetting.instance.isNotAutoSelectMonster);
            this._settingItemArrayRight.push({type:"选取目标", list:_loc_1});
            _loc_1 = new Array();
            _loc_1.push(SystemSetting.instance.mouseRightUIKey);
            _loc_1.push(SystemSetting.instance.mouseRightSceneKey);
            this._settingItemArrayRight.push({type:"鼠标设置", list:_loc_1});
            _loc_1 = new Array();
            _loc_1.push(SystemSetting.instance.isShortcutShowSecond);
            _loc_1.push(SystemSetting.instance.isLockShortcut);
            this._settingItemArrayRight.push({type:"其他设置", list:_loc_1});
            super.configUI();
            this.addEventListener(Event.REMOVED_FROM_STAGE, this.onRemoveFromStage);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            var _loc_1:Object = null;
            var _loc_2:int = 0;
            var _loc_5:SystemSetBigItem = null;
            super.createDisposedChildrenImpl();
            pushUIToDisposeVec(UIFactory.bg(17, 67, 231, 306, this));
            pushUIToDisposeVec(UIFactory.bg(251, 67, 231, 306, this));
            var _loc_3:* = UICompomentPool.getUICompoment(GBox);
            this._leftBox = _loc_3;
            _loc_3.direction = GBoxDirection.VERTICAL;
            var _loc_4:* = this._settingItemArrayLeft.length;
            _loc_2 = 0;
            while (_loc_2 < _loc_4)
            {
                
                _loc_1 = this._settingItemArrayLeft[_loc_2];
                _loc_5 = UICompomentPool.getUICompoment(SystemSetBigItem);
                _loc_5.updateData(_loc_1.type, _loc_1.list);
                _loc_3.addChild(_loc_5);
                _loc_2++;
            }
            pushUIToDisposeVec(_loc_3);
            _loc_3.resetPosition2();
            if (!this._scrollPaneLeft)
            {
                this._scrollPaneLeft = UIFactory.gScrollPanel(0, 0, 220, 300, this);
            }
            this._scrollPaneLeft.source = _loc_3;
            this._scrollPaneLeft.horizontalScrollPolicy = ScrollPolicy.OFF;
            this._scrollPaneLeft.verticalScrollPolicy = ScrollPolicy.ON;
            this._scrollPaneLeft.update();
            UIFactory.setObjAttri(this._scrollPaneLeft, 23, 70, -1, -1, this);
            _loc_3 = UICompomentPool.getUICompoment(GBox);
            this._rightBox = _loc_3;
            _loc_3.direction = GBoxDirection.VERTICAL;
            _loc_4 = this._settingItemArrayRight.length;
            _loc_2 = 0;
            while (_loc_2 < _loc_4)
            {
                
                _loc_1 = this._settingItemArrayRight[_loc_2];
                _loc_5 = UICompomentPool.getUICompoment(SystemSetBigItem);
                _loc_5.updateData(_loc_1.type, _loc_1.list);
                _loc_3.addChild(_loc_5);
                _loc_2++;
            }
            pushUIToDisposeVec(_loc_3);
            _loc_3.resetPosition2();
            if (!this._scrollPaneRight)
            {
                this._scrollPaneRight = UIFactory.gScrollPanel(0, 0, 220, 300, this);
            }
            this._scrollPaneRight.source = _loc_3;
            this._scrollPaneRight.horizontalScrollPolicy = ScrollPolicy.OFF;
            this._scrollPaneRight.verticalScrollPolicy = ScrollPolicy.ON;
            this._scrollPaneRight.update();
            UIFactory.setObjAttri(this._scrollPaneRight, 259, 70, -1, -1, this);
            var _loc_6:* = UIFactory.gTextField("音乐", 60, 375, 40, 22, this);
            _loc_6.mouseEnabled = false;
            pushUIToDisposeVec(_loc_6);
            this._bgMusicBar = UICompomentPool.getUICompoment(IconProgressBar);
            this._bgMusicBar.setBg(ImagesConst.SystemSetBarBg, true, 133, 10);
            this._bgMusicBar.setProgress(ImagesConst.SystemSetBar, false, 1, 1, 131, 9);
            this._bgMusicBar.setLabel(BaseProgressBar.ProgressBarTextNone);
            this._bgMusicBar.setIconBtnStyle(ImagesConst.SystemSetPoint_upSkin, 19, 19);
            this._bgMusicBar.isCanDrag = true;
            this._bgMusicBar.setValue(SystemSetting.instance.bgMusic.displayValue, 100);
            this._bgMusicBar.configEventListener(Event.CHANGE, this.onBgMusicChange);
            UIFactory.setObjAttri(this._bgMusicBar, 96, 380, -1, -1, this);
            _loc_6 = UIFactory.gTextField("音效", 260, 375, 40, 22, this);
            _loc_6.mouseEnabled = false;
            pushUIToDisposeVec(_loc_6);
            this._effectMusicBar = UICompomentPool.getUICompoment(IconProgressBar);
            this._effectMusicBar.setBg(ImagesConst.SystemSetBarBg, true, 133, 10);
            this._effectMusicBar.setProgress(ImagesConst.SystemSetBar, false, 1, 1, 131, 9);
            this._effectMusicBar.setLabel(BaseProgressBar.ProgressBarTextNone);
            this._effectMusicBar.setIconBtnStyle(ImagesConst.SystemSetPoint_upSkin, 19, 19);
            this._effectMusicBar.isCanDrag = true;
            this._effectMusicBar.setValue(SystemSetting.instance.effectMusic.displayValue, 100);
            this._effectMusicBar.configEventListener(Event.CHANGE, this.onEffectMusicChange);
            UIFactory.setObjAttri(this._effectMusicBar, 296, 380, -1, -1, this);
            this._forbitMusicCheckBox = UIFactory.checkBox("静音", 60, 398, 100, 28, this);
            this._forbitMusicCheckBox.configEventListener(Event.CHANGE, this.onCBMusicChange);
            this._forbitMusicCheckBox.selected = Boolean(SystemSetting.instance.isForbidMusic.displayValue);
            this._btnReset = UIFactory.gButton("默认设置", 162, 402, 70, 22, this);
            this._btnSave = UIFactory.gButton("保存设置", 267, 402, 70, 22, this);
            this._btnReset.configEventListener(MouseEvent.CLICK, this.onClickReset);
            this._btnSave.configEventListener(MouseEvent.CLICK, this.onClickSave);
            Dispatcher.addEventListener(EventName.ForbitMusicChange, this.onForbitMusicChange);
            return;
        }// end function

        protected function onBgMusicChange(event:Event) : void
        {
            SystemSetting.instance.bgMusic.displayValue = int(this._bgMusicBar.value);
            this.updateBgMusic();
            return;
        }// end function

        protected function onEffectMusicChange(event:Event) : void
        {
            SystemSetting.instance.effectMusic.displayValue = int(this._effectMusicBar.value);
            this.updateEffectMusic();
            return;
        }// end function

        protected function onForbitMusicChange(event:Event) : void
        {
            this._forbitMusicCheckBox.selected = Boolean(SystemSetting.instance.isForbidMusic.displayValue);
            this.updateBgMusic();
            this.updateEffectMusic();
            return;
        }// end function

        protected function onCBMusicChange(event:Event) : void
        {
            SystemSetting.instance.isForbidMusic.displayValue = int(this._forbitMusicCheckBox.selected);
            Dispatcher.dispatchEvent(new DataEvent(EventName.ForbitMusicChange, int(this._forbitMusicCheckBox.selected)));
            return;
        }// end function

        protected function updateBgMusic() : void
        {
            SoundManager.instance.musicVolume = SystemSetting.instance.isForbidMusic.displayValue ? (0) : (int(this._bgMusicBar.value) / 100);
            return;
        }// end function

        protected function updateEffectMusic() : void
        {
            SoundManager.instance.effectSoundVolune = SystemSetting.instance.isForbidMusic.displayValue ? (0) : (int(this._effectMusicBar.value) / 100);
            return;
        }// end function

        protected function onClickReset(event:MouseEvent) : void
        {
            SystemSetting.instance.resetToDefault();
            this.refreshDisplay();
            this.save();
            return;
        }// end function

        protected function onClickSave(event:MouseEvent) : void
        {
            SystemSetting.instance.updateToServer();
            this.save();
            return;
        }// end function

        protected function onRemoveFromStage(event:Event) : void
        {
            SystemSetting.instance.recover();
            return;
        }// end function

        public function refreshDisplay() : void
        {
            var _loc_2:int = 0;
            var _loc_3:SystemSetBigItem = null;
            var _loc_1:* = this._leftBox.numChildren;
            _loc_2 = _loc_1 - 1;
            while (_loc_2 >= 0)
            {
                
                _loc_3 = this._leftBox.getChildAt(_loc_2) as SystemSetBigItem;
                _loc_3.refreshDisplay();
                _loc_2 = _loc_2 - 1;
            }
            this._leftBox.resetPosition2();
            this._scrollPaneLeft.update();
            _loc_1 = this._rightBox.numChildren;
            _loc_2 = _loc_1 - 1;
            while (_loc_2 >= 0)
            {
                
                _loc_3 = this._rightBox.getChildAt(_loc_2) as SystemSetBigItem;
                _loc_3.refreshDisplay();
                _loc_2 = _loc_2 - 1;
            }
            this._rightBox.resetPosition2();
            this._scrollPaneRight.update();
            this._bgMusicBar.setValue(SystemSetting.instance.bgMusic.value, 100);
            this._effectMusicBar.setValue(SystemSetting.instance.effectMusic.value, 100);
            this._forbitMusicCheckBox.selected = this._bgMusicBar.value == 0 && this._effectMusicBar.value == 0;
            this.updateBgMusic();
            this.updateEffectMusic();
            return;
        }// end function

        protected function save() : void
        {
            var _loc_1:* = new Object();
            _loc_1.type = SystemSettingType.SystemSetting;
            _loc_1.value = SystemSetting.instance.getServerStr();
            Dispatcher.dispatchEvent(new DataEvent(EventName.SystemSettingSava, _loc_1));
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._btnSave.dispose(param1);
            this._btnSave = null;
            this._btnReset.dispose(param1);
            this._btnReset = null;
            this._leftBox = null;
            this._rightBox = null;
            this._bgMusicBar.dispose(param1);
            this._bgMusicBar = null;
            this._effectMusicBar.dispose(param1);
            this._effectMusicBar = null;
            this._forbitMusicCheckBox.dispose(param1);
            Dispatcher.removeEventListener(EventName.ForbitMusicChange, this.onForbitMusicChange);
            super.disposeImpl(param1);
            return;
        }// end function

    }
}
